package tmp_GetTypeFromClass;

import java.io.*;
import java.util.*;
import zclTool.*;

class MyData implements Comparable<MyData> {
	public MyData(String[] line) {
		this.size = Double.parseDouble(line[0]);
		this.infoname = line[1];
		 this.typename = line[2];
	}

	public int compareTo(MyData other) {
		double result =  other.size- this.size ;
		return result==0?0:result>0?1:-1;
	}
	double size;
	String infoname;
	String typename;
}

public class Select10TypeForClass {

	/**
	 * @param args
	 */
//count_class_type count_class_type_10big
	//cond_prop_class_type cond_prop_class_type_10big
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		DelimitedReader dr = new DelimitedReader(args[0]);
		ArrayList<String[]> lines = new ArrayList<String[]>();
		OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(
				args[1]), "utf-8");
		String listClass = "";
		String[] line;
		while ((line = dr.read()) != null) {
			String classNow = line[1];
			if (classNow.equals(listClass)) {
				String[] temp = new String[line.length];
				System.arraycopy(line, 0, temp, 0, line.length);
				lines.add(temp);
			} else {
				// deal with the lines
				MyData []my = deal(lines);
				for(int i=0;i<my.length ;i++){
					if(i>10 && my[i].size<0.9)break;
					if(!my[i].typename.equals("common/topic")){
						System.out.println(my[i].size+"\t"+my[i].infoname+"\t"+my[i].typename);
						osw.write(my[i].size+"\t"+my[i].infoname+"\t"+my[i].typename+"\n");
					}
				}
				lines = new ArrayList<String[]>();
				listClass = line[1];
				lines.add(line);
				
			}
		}
		dr.close();
	}

	public static MyData[] deal(ArrayList<String[]> lines) {
		MyData[] my = new MyData[lines.size()];
		for(int i = 0;i<lines.size();i++){
			my[i]= new MyData(lines.get(i));
		}
		Arrays.sort(my);
		return my;
	}

}
